﻿module IronLua.Internals.api
//
//open IronLua.Runtime
//
//[<Literal>]
//let LUA_MULTRET = -1
//[<Literal>]
//let RESERVEDSLOT = 5
//[<Literal>]
//let LUA_VERSION = "Lua 5.2.0 (IronLua)"
//
//[<Literal>]
//let LUAI_MAXSTACK = 1000000
//let LUAI_FIRSTPSEUDOIDX = (-LUAI_MAXSTACK - 1000)
//let LUA_REGISTRYINDEX = LUAI_FIRSTPSEUDOIDX
//let LUA_MAXUPVAL = 0xff
//
//let lualock (t : Thread) = ()
//let luaunlock (t : Thread) = ()
//
//let rec absindex (thread : Thread, index : int) : int = 
//    if idx > 0 || idx <= LUA_REGISTRYINDEX 
//    then idx
//    else (thread.Stack.TopIndex - thread.CallStack.FuncIndex + idx)   
//
//and arith (thread : Thread, op : LuaArithOperation) : int = 
//    failwith "arith"
//
//and atpanic (thread : Thread, panicfn : LuaPrototype) : LuaPrototype = 
//    let old = thread.State.Panic
//    thread.State.Panic <- panicfn
//    old
//
//and call (thread : Thread, nargs : int, nresults : int) : unit = 
//    failwith "call"
//
//and callk (thread : Thread, nargs : int, results : int, ctx : int, continuation : LuaPrototype) : unit =
//    failwith "callk"
//
//and check(thread : Thread, cond : bool, errmsg : string) = ()
//    
//and checknelems(thread : Thread, n : int) : unit = ()    
//
//and checkstack (thread : Thread, extra : int) : bool =
//    failwith "checkstack"
//
//and compare (thread : Thread, index1 : int, index2 : int, op : int) : int =
//    failwith "compare"
//
//and concat (thread : Thread, n : int) : unit =
//    failwith "concat"
//
//and copy (thread : Thread, fromidx : int, toidx : int) : unit = 
//    failwith "copy"
//
//and createtable (thread : Thread, narr : int, nrec : int) : unit = 
//    failwith "createtable"
//
//and dump (thread : Thread, writer : System.IO.StreamWriter, data : System.Collections.Generic.IList<byte>) =
//    failwith "dump"
//
//and equalobj(thread : Thread, v1 : LuaValue, v2 : LuaValue) : bool = 
//    failwith "equalobj"
//    
//and error (thread : Thread) : int =
//    failwith "error"
//
//and gc (thread : Thread, what : int, data : int) : int =
//    failwith "gc"
//
//and getctx (thread : Thread) : (LuaResult * int)= 
//    failwith "getctx"
//
//and getuservalue (thread : Thread, index : int) : unit = 
//    failwith "getuservalue"
//
//and getfield (thread : Thread, index : int, k : string) : unit = 
//    failwith "getfield"
//
//and getglobal (thread : Thread, name : string) : unit = 
//    failwith "getglobal"
//
//and getmetatable (thread : Thread, index : int) : bool =
//    failwith "getmetatable"
//
//and gettable (thread : Thread, index : int) : unit =
//    failwith "gettable"
//
//and gettop (thread : Thread) : int = 
//    thread.Stack.TopIndex - thread.CallStack.FuncIndex
//
//and growstack (thread : Thread, size : int) : unit = 
//    failwith "growstack"
//
//and index2addr (thread : Thread, index : int) : LuaValue = 
//    match idx with
//    | _ when idx > 0 -> let valueidx = thread.CallStack.FuncIndex + idx
//                        check(thread, idx <= thread.CallStack.FuncIndex + 1, "unacceptable index")
//                        if valueidx >= thread.Stack.TopIndex then LuaValue.Nil
//                        else thread.Stack.[valueidx]
//    | _ when idx > LUA_REGISTRYINDEX -> LuaValue.Nil
//    | _ when idx = LUA_REGISTRYINDEX -> LuaValue.Nil
//    | _ ->  let upidx = LUA_REGISTRYINDEX - idx
//            check(thread, upidx <= LUA_MAXUPVAL + 1, "upvalue index too large")
//            let fn = thread.CallStack.FuncValue
//            match fn.Type with
//            | LuaValueType.ClrClosure
//            | LuaValueType.Function ->          LuaValue.Nil
//            | _ ->                              LuaValue.Nil
//
//and insert (thread : Thread, index : int) : unit =
//    failwith "insert"
//
//and isboolean (thread : Thread, index : int) : bool =
//    failwith "isboolean"
//
//and isclrfunction (thread : Thread, index : int) : bool =
//    match type'(thread, index) with
//    | LuaValueType.LightClrFunction 
//    | LuaValueType.ClrClosure ->    true
//    | _ ->                          false
//
//and isfunction (thread : Thread, index : int) : bool = 
//    failwith "isfunction"
//
//and islightuserdata (thread : Thread, index : int) : bool =
//    failwith "islightuserdata"
//
//and isnil (thread : Thread, index : int) : bool =
//    failwith "isnil"
//
//and isnone (thread : Thread, index : int) : bool =
//    failwith "isnone"
//
//and isnoneornil (thread : Thread, index : int) : bool = 
//    failwith "isnoneornil"
//
//and isnumber (thread : Thread, index : int) : bool = 
//    let value = index2addr(thread, index)
//    let ok, num = tonumber(value)
//    ok
//
//and isstring (thread : Thread, index : int) : bool = 
//    match type'(thread, index) with
//    | LuaValueType.String 
//    | LuaValueType.Number -> true
//    | _ -> false
//
//and istable (thread : Thread, index : int) : bool = 
//    failwith "istable"
//
//and isthread (thread : Thread, index : int) : bool = 
//    failwith "isthread"
//
//and isuserdata (thread : Thread, index : int) : bool = 
//    let value = index2addr(thread, index)
//    match value.Type with
//    | LuaValueType.Userdata 
//    | LuaValueType.LightUserdata -> true
//    | _ ->                          false
//
//and isvalid (value : LuaValue) : bool =
//    match value.Type with
//    | LuaValueType.None -> false
//    | _ ->                 true
//
//and len (thread : Thread, index : int) : unit = 
//    failwith "len"
//
//and load(thread : Thread, 
//         reader : (Thread * byte array) -> string, 
//         data : System.Collections.Generic.IList<byte>, 
//         source : string, 
//         mode : string) : LuaResult = 
//    failwith "load"
//
//and newtable (thread : Thread) : unit =
//    failwith "newtable"
//
//and newthread (thread : Thread) : Thread = 
//    failwith "newthread" 
//
//and newuserdata (thread : Thread) : obj =
//    failwith "newuserdata"
//
//and next (thread : Thread, index : int) : bool =
//    failwith "next"
//
//and pcall (thread : Thread, nargs : int, nresults : int, errfun : int) : LuaResult = 
//    failwith "pcall"
//
//and pcallk (thread : Thread, nargs : int, nresults : int, errfun : int, ctx : int, continuation : LuaPrototype) : LuaResult =
//    failwith "pcallk"
//
//and pop (thread : Thread, n : int) : unit = 
//    failwith "pop"
//
//and pushboolean (thread : Thread, b : bool) : unit =
//    failwith "pushboolean"
//
//and pushclrclosure (thread : Thread, clo : ClrClosure, n : int) : unit =
//    failwith "pushclrclosure"
//
//and pushclrfunction (thread : Thread, fn : LuaPrototype) : unit =
//    // pushclrclosure(thread, fn, 0)
//    failwith "pushclrfunction"
//
//and pushfstring (thread : Thread, fmt : string, values : obj array) : unit = 
//    failwith "pushfstring"
//
//and pushglobaltable (thread : Thread) : unit =
//    failwith "pushglobaltable"
//
//and pushinteger (thread : Thread, n : int) : unit =
//    failwith "pushinteger"
//
//and pushlightuserdata (thread : Thread, p : obj) : unit = 
//    failwith "pushlightuserdata"
//
//and pushstring (thread : Thread, str : string) : LuaValue = 
//    failwith "pushstring"
//
//and pushliteral (thread : Thread, str : string) : unit =
//    pushstring(thread, str) |> ignore
//
//and pushnil (thread : Thread) : unit =
//    failwith "pushnil"
//
//and pushnumber (thread : Thread, n : LuaValue) : unit =
//    failwith "pushnumber"
//
//and pushthread (thread : Thread) : bool =
//    failwith "pushthread"
//
//and pushvalue (thread : Thread, index : int) : unit =
//    lualock(thread);
//    setobj2s(thread, thread.Stack.TopIndex, index2addr(thread, idx))
//    incrtop(thread);
//    luaunlock(thread);
//
//and rawequal (thread : Thread, index1 : int, index2 : int) : bool =
//    let v1 = index2addr(thread, index1)
//    let v2 = index2addr(thread, index2)
//    if isvalid(v1) && isvalid(v2) then rawequalobj(v1, v2)
//    else false    
//
//and rawequalobj(v1, v2) : bool = 
//    ttisequal(v1, v2) && equalobj(null, v1, v2)
//
//and rawget (thread : Thread, index : int) : unit =
//    failwith "rawget"
//
//and rawgeti (thread : Thread, index : int, n : int) : unit =
//    failwith "rawgeti"
//
//and rawlen (thread : Thread, index : int) : int =
//    failwith "rawlen"
//
//and rawset (thread : Thread, index : int) : unit =
//    failwith "rawset"
//
//and rawseti (thread : Thread, index : int, n : int) : unit =
//    failwith "rawseti"
//
//and register (thread : Thread, name : string, fn : LuaPrototype) : unit =
//    failwith "register"
//
//and remove (thread : Thread, index : int) : unit =
//    failwith "remove"
//
//and replace (thread : Thread, index : int) : unit =
//    failwith "replace"
//
//and resume (thread : Thread, narg : int) : LuaResult =  
//    failwith "resume"
//
//and setuservalue (thread : Thread, index : int) : bool =
//    failwith "setuservalue"
//
//and setfield (thread : Thread, index : int, k : string) : unit =
//    failwith "setfield"
//
//and setglobal (thread : Thread, name : string) : unit = 
//    failwith "setglobal"
//
//and setmetatable (thread : Thread, index : int) : bool =
//    failwith "setmetatable"
//
//and settable (thread : Thread, index : int) : unit = 
//    failwith "settable"
//
//and settop (thread : Thread, index : int) : unit =
//    failwith "settop"
//
//and status (thread : Thread) : LuaResult =
//    failwith "status"
//
//and toboolean (thread : Thread, index : int) : bool = 
//    failwith "toboolean"
//
//and toclrfunction (thread : Thread, index : int) : obj =
//    failwith "toclrfunction"
//
//and tonumberx (thread : Thread, index : int) : (LuaValue * bool) =
//    failwith "tonumberx"
//
//and tointegerx (thread : Thread, index : int) : (int * bool) = 
//    failwith "tointeger"
//
//and tothread (thread : Thread, index : int) : Thread = 
//    failwith "tothread"
//
//and touserdata (thread : Thread, index : int) : obj = 
//    failwith "touserdata"
//
//and ttisequal(v1 : LuaValue, v2 : LuaValue) : bool =
//    v1.Type = v2.Type
//
//and type' (thread : Thread, index : int) : LuaValueType =
//    let value = index2addr(thread, index)
//    value.Type
//    
//and typename (thread : Thread, t : LuaValueType) : string = 
//    match t with
//    | LuaValueType.None ->          "no value"
//    | LuaValueType.Nil ->           "nil"
//    | LuaValueType.Boolean ->       "boolean"
//    | LuaValueType.Userdata ->      "userdata"
//    | LuaValueType.Number ->        "number"
//    | LuaValueType.String ->        "string"
//    | LuaValueType.Table  ->        "table"
//    | LuaValueType.Function 
//    | LuaValueType.ClrClosure  ->   "function"
//    | LuaValueType.LightUserdata -> "userdata"
//    | LuaValueType.Thread ->        "thread"
//    | LuaValueType.Prototype ->     "proto"
//    | LuaValueType.Upvalue ->       "upval"
//    | _ ->                          "?"
//
//and version (thread : Thread) : double =
//    failwith "version"
//
//and xmove (fromthread : Thread, tothread : Thread, n : int) = 
//    failwith "xmove"
//
//and yield' (thread : Thread, nresults : int) : int = 
//    failwith "luayield"
//
//and yieldk (thread : Thread, nresults : int, ctx : int, k : LuaValue) : int = 
//    failwith "luayieldk"
//
//and gethook (thread : Thread) : obj = 
//    failwith "gethook"
//
//and gethookcount (thread : Thread) : int =
//    failwith "gethookcount"
//
//and gethookmask (thread : Thread) : int = 
//    failwith "gethookmask"
//
//and getinfo (thread : Thread, what : string, ar : obj ref) : int =
//    failwith "getinfo"
//
//and getlocal (thread : Thread, ar : obj ref, n : int) : string = 
//    failwith "getlocal"
//
//and getstack (thread : Thread, level : int, ar : obj ref) : int =
//    failwith "getstack"
//
//and getupvalue (thread : Thread, funcindex : int, n : int) : string = 
//    failwith "getupvalue"
//
//and sethook (thread : Thread, f : LuaValue, mask : int, count : int) : int =
//    failwith "sethook"
//
//and setlocal (thread : Thread, ar : obj ref, n : int) : string = 
//    failwith "setlocal"
//
//and setupvalue (thread : Thread, funcindex : int, n : int) : string = 
//    failwith "setupvalue"
//
//and upvalueid (thread : Thread, funcindex : int, n : int) : int64 = 
//    failwith "upvalueid"
//
//and upvaluejoin (thread : Thread, fidx1 : int, n1 : int, fidx2 : int, n2 : int) : unit =
//    failwith "upvaluejoin"
//
//and argcheck (thread : Thread, cond : int, narg : int, extramsg : string) : unit =
//    failwith "argcheck"
//
//and argerror (thread : Thread, narg : int, extramsg : string) : int = 
//    failwith "argerror"
//
//and callmeta (thread : Thread, o : int, e : string) : int =
//    failwith "callmeta"
//
//and checkany (thread : Thread, narg : int) : unit = 
//    failwith "checkany"
//
//and checkint (thread : Thread, narg : int) : int =
//    failwith "checkint"
//
//and checkinteger (thread : Thread, narg : int) : int = 
//    failwith "checkinteger"
//
//and checklong (thread : Thread, narg : int) : int64 =
//    failwith "checklong"
//
//and checkstring (thread : Thread, narg : int) : string =
//    failwith "checkstring"
//
//and checknumber (thread : Thread, narg : int) : double =
//    failwith "checknumber"
//
//and checkoption (thread : Thread, narg : int, def : string, lst : string array) : int = 
//    failwith "checkoption"
//
//and checktype (thread : Thread, narg : int, t : LuaValueType) : unit = 
//    failwith "checktype"
//
//and checkudata (thread : Thread, narg : int, tname : string) : LuaValue = 
//    failwith "checkudata"
//
//and loadfile (thread : Thread, filename : string) : bool = 
//    failwith "loadfile"
//
//and loadstring (thread : Thread, s : string) : bool = 
//    failwith "loadstring"
//
//and dofile (thread : Thread, filename : string) : bool =
//    loadfile(thread, filename) && (pcall(thread, 0, -1, 0) = LuaResult.OK)
//
//and dostring (thread : Thread, str : string) : bool =
//    loadstring(thread, str) && (pcall(thread, 0, -1, 0) = LuaResult.OK)
//
//and errorf (thread : Thread, fmt : string, [<System.ParamArrayAttribute>] values : obj array) = 
//    failwith "error"
//
//and findtable (thread : Thread, index : int, fname : string) : unit =
//    failwith "findtable"
//
//and getmetafield (thread : Thread, o : int, e : string) : int = 
//    failwith "getmetafield"
//
//and getmetatablereg (thread : Thread, tname : string) : unit =
//    failwith "getmetatablereg"
//
//and metalen (thread : Thread, index : int) : int =
//    failwith "metalen"
//
//// -----
//
//and tonumber(value : LuaValue) : (bool * LuaValue) =
//    failwith "tonumber"